package com.hspedu.newData.LCR;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-17 
 * @Version: 1.0
 */

public class LCR145判断对称二叉树 {

    public boolean checkSymmetricTree(TreeNode root) {

        if (root == null) return true;

        return dfs(root.left,root.right);

    }

    public boolean dfs(TreeNode left,TreeNode right){
        if (left == null && right == null) return true;

        if (left == null || right == null || left.val != right.val){
            return false;
        }

        return dfs(left.left, right.right) && dfs(left.right,right.left);

    }
}
